package com.stone.framework.core.context;

import java.util.Optional;

public class UUIDContext {

    private final ThreadLocal<String> threadLocal = new ThreadLocal<>();

    public Optional<String> get() {
        return Optional.ofNullable(threadLocal.get());
    }

    public void set(String uuid) {
        threadLocal.set(uuid);
    }

    public void remove() {
        threadLocal.remove();
    }

    public static UUIDContext build() {
        return SingletonHandler.SINGLETON;
    }

    private static class SingletonHandler {
        private static final UUIDContext SINGLETON = new UUIDContext();
    }

    private UUIDContext() {

    }

}
